<template>
	<view class="wapper">
		<u-navbar :autoBack="true" leftIconColor="#fff" height="90rpx" titleStyle="color:#fff" title="保养工单"
			:bgColor="bgColor">
		</u-navbar>
		<view class="clear"></view>
		<view class="con-con">
			<view class="con-title">
				{{detailInfo.workOrderStatusStr}}
			</view>
			<view class="content">
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-title">
							工单编号
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-title">
							工单类型
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-title">
							保养类型
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.workOrderNo}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.workOrderTypeStr}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.maintainTypeStr}}
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-title">
							船舶名称
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-title">
							发起人
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-title">
							发起时间
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.boatName}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.createByName}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							<template v-if="detailInfo.createTime">
								{{detailInfo.createTime}}
							</template>
							<template v-else>-</template>

						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-title">
							船舶运行时间
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-title">
							上次保养结束时间
						</view>
					</u-col>
					<u-col span="4">

					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.runningHours}}h
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.lastEndTime || '-'}}
						</view>
					</u-col>
					<u-col span="4">

					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							计划保养时间
						</view>

					</u-col>


				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.planStartTime}} ~ {{detailInfo.planEndTime}}
						</view>

					</u-col>


				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							保养备注
						</view>

					</u-col>


				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.remark || '-'}}
						</view>

					</u-col>


				</u-row>
			</view>
			<view class="pro-content">
				<view class="pro-title">
					保养项目
				</view>
				<view class="pro-header">
					<view class="head-index">
						序号
					</view>
					<view class="head-one">
						保养设备
					</view>
					<view class="head-two">
						保养项目
					</view>
				</view>
				<template v-if="detailInfo.projectInfoList && detailInfo.projectInfoList.length>0">
					<view class="pro-list clearfix" v-for="(item,index) in detailInfo.projectInfoList" :key="index">
						<view class="list-index">{{index+1}}</view>
						<view class="list-one">{{item.equipmentName}}</view>
						<view class="list-two" v-html="item.content.replace(/\n/g,'<br/>')"></view>
					</view>

				</template>
				<view class="clear"></view>
			</view>
			<view class="content"
				v-if="detailInfo.workOrderStatus===4 ||(detailInfo.workOrderStatus===3 && detailInfo.maintainType>=3)">
				<view class="result-title">
					保养结果
				</view>
				<view class="main-bg">
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-title">
								实际保养时间
							</view>
					
						</u-col>
					
					
					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-val">
								{{detailInfo.actualStartTime}} ~{{detailInfo.actualEndTime}}
							</view>
					
						</u-col>
					
					
					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-title">
								实际保养人
							</view>
					
						</u-col>
					
					
					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-val">
								{{maintainByNameList}}
							</view>
					
						</u-col>
					
					
					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-title">
								保养情况
							</view>
					
						</u-col>
					
					
					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-val">
								{{detailInfo.maintainResult}}
							</view>
					
						</u-col>
					
					
					</u-row>
				</view>

				
			</view>
			<view class="content" v-if="detailInfo.workOrderStatus===4 && detailInfo.maintainType>2">
				<view class="result-title">
					保养验收
				</view>

				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							验收结果
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.checkResultStr}}
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							验收人
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.checkByName}}
						</view>

					</u-col>


				</u-row>
			</view>
			<view class="content" v-if="detailInfo.workOrderStatus===5">
				<view class="result-title">
					审批结果
				</view>

				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							审批结果
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.workOrderStatusStr}}
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							驳回原因
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.rejectReason}}
						</view>

					</u-col>


				</u-row>
			</view>
			<stepsList :approvalRecordDtoList="detailInfo.approvalRecordDtoList"
				v-if="detailInfo.approvalRecordDtoList && detailInfo.approvalRecordDtoList.length>0"></stepsList>

		</view>
		<!-- 填写保养结果 -->
		<view class="footer" @click="navTo('/subMaintenance/maintain/submitResult?id='+id)"
			v-if="detailInfo.workOrderStatus===2  && detailInfo.hasAuth===1">
			填写保养结果
		</view>
		<!-- 审批结果 -->
		<Approval v-if="detailInfo.workOrderStatus===1 && detailInfo.maintainType!==1  && detailInfo.hasAuth===1"
			:id="id" type="1" @getDetail="getDetail"></Approval>
		<!-- 验收结果 -->
		<Check v-if="detailInfo.workOrderStatus===3 && detailInfo.maintainType>2" :id="id" type="1"
			@getDetail="getDetail"></Check>

	</view>
</template>

<script>
	import {
		getWorkOrderDetail
	} from '@/api/maintain.js'
	import stepsList from '@/components/steps/stepsList'
	import Approval from '@/components/approval/index'
	import Check from '@/components/check/index'
	export default {
		components: {
			stepsList,
			Approval,
			Check
		},
		filters: {

		},
		data() {
			return {
				bgColor: '#7291F1',
				id: null,
				detailInfo: {},
				maintainByNameList: []

			}
		},
		onLoad(option) {
			this.id = option.id || ''
		},
		onShow() {
			this.getDetail()
		},
		created() {

		},

		methods: {
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			getDetail() {
				const id = this.id
				this.detailInfo = {}
				getWorkOrderDetail({
					id
				}).then(response => {
					this.detailInfo = response.data

					if (this.detailInfo.approvalUserList && this.detailInfo.approvalUserList.length > 0) {
						let approvalUserList = []
						for (let i = 0; i < this.detailInfo.approvalUserList.length; i++) {
							approvalUserList.push(this.detailInfo.approvalUserList[i].userName)
						}
						this.approvalUserList = approvalUserList.toString()

					}
					if (this.detailInfo.maintainByNameList && this.detailInfo.maintainByNameList.length > 0) {
						this.maintainByNameList = this.detailInfo.maintainByNameList.join(",")
					}
					// const endData = {
					// 	planTime: [response.data.planStartTime, response.data.planEndTime],
					// 	...response.data
					// }
					// this.editForm = endData
					// if (this.editForm.projectInfoList && this.editForm.projectInfoList.length > 0) {
					// 	let newArr = []
					// 	for (let i = 0; i < this.editForm.projectInfoList.length; i++) {
					// 		newArr.push(this.editForm.projectInfoList[i].projectId)
					// 	}
					// 	this.editForm.projectIdList = [...newArr]

					// } else {
					// 	this.editForm.projectInfoList = []
					// }


				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.wapper {
		width: 100vw;
		min-height: 100vh;
		background: #F5F7F9 url('@/static/image/detail/maintain_bg.png') no-repeat top center;
		background-size: 100% auto;
		padding-bottom: 70rpx;

		.clear {
			clear: both;
		}

		.con-con {
			margin: 0 26rpx;
			padding-top: 126rpx;

			.con-title {
				font-size: 50rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 70rpx;
				margin-bottom: 20rpx;
				padding-top: 54rpx;
			}

			.content {
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 30rpx 18rpx;
				box-sizing: border-box;
				margin-bottom: 10rpx;
				.main-bg{
					background: #F5F7F9;
					border-radius: 16rpx;
					padding: 34rpx 24rpx;
				}

				.result-title {
					font-size: 28rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 25rpx;
				}

				.item-title {
					font-size: 22rpx;
					font-weight: 400;
					color: #909399;
					margin-bottom: 10rpx;
				}

				.item-val {
					font-size: 27rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 40rpx;
				}

			}

			.pro-content {
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 30rpx 18rpx;
				box-sizing: border-box;
				margin-bottom: 10rpx;

				.pro-title {
					font-size: 28rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 25rpx;
				}

				.pro-header {
					background: #F5F7FA;
					border-radius: 3rpx;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 22rpx;
					font-weight: 400;
					color: #8C99A7;

					.head-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.head-one {
						width: 184rpx;
						float: left;
					}

					.head-two {
						float: left;
						width: calc(100% - 294rpx);
					}
				}

				.pro-list {
					padding: 10rpx 0;
					font-size: 22rpx;
					font-weight: 400;
					color: #303133;
					min-height: 40rpx;

					.list-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.list-one {
						width: 184rpx;
						float: left;
					}

					.list-two {
						float: left;
						width: calc(100% - 294rpx);
					}

					&:nth-child(2n) {
						background: #F5F7FA;
					}

					&::after {
						clear: both;
					}
				}
			}


		}

		.footer {
			width: 690rpx;
			height: 104rpx;
			background: #407FFF;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			margin: 70rpx auto 0 auto;
		}
	}
</style>
